/*******************************************************************************
 * Copyright（C） CETC-32
 * @file:User.java
 * @Description：
 * @Author ：徐文远
 * @version：1.0
 * @date ： 2021/3/9 上午10:03
 ******************************************************************************/

package com.cetc32.webutil.common.util;

import com.cetc32.webutil.common.bean.LoginUser;
/***
 *
 * **/
public class SecurityUserUtil {
    private static ThreadLocal<LoginUser> userHold= new ThreadLocal<>();
    private static ThreadLocal<String> sysCode = new ThreadLocal<>();
    public static void setUser(LoginUser user,String syscode){
        userHold.remove();
        userHold.set(user);
        sysCode.remove();
        sysCode.set(syscode);
    }
    public static LoginUser getUser(){
        if(null != userHold.get())
            return userHold.get();
        return null;
    }
    public static boolean isAdmin(){
        if( getUser() ==null)
            return false;
        return getUser().isAdminOf(sysCode.get());
    }
}
